package com.app.backend.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: SwaggerConfig
 * @description:
 * @author: Zhun.Xiao
 * @create: 2019-09-16 22:28
 **/

@Configuration
public class SwaggerConfig {


    @Bean
    public Docket createRestApi() {
        ParameterBuilder tokenParam = new ParameterBuilder();
        List<Parameter> params = new ArrayList<Parameter>();
        tokenParam.name("access-token").description("accessToken令牌")
                .modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        params.add(tokenParam.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.app.backend.api.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(params);
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("app-backend-api")
                .description("app-api")
                .version("1.0")
                .build();
    }

}